package com.longjianghuasheng.logistics.base

import android.annotation.SuppressLint
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.Typeface
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import androidx.databinding.ViewDataBinding
import com.longjianghuasheng.logistics.R
import com.xuexiang.xui.widget.actionbar.TitleBar


//带title的
abstract class BaseTitleFragment<VM : BaseMultiStateViewModel, DB : ViewDataBinding> :
    BaseMultiStateFragment<VM, DB>(), Refresh {


    lateinit var titleBar: TitleBar

    //该类绑定的ViewDataBinding
    @SuppressLint("NewApi", "UseCompatTextViewDrawableApis")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        val flTop = view.findViewById<FrameLayout>(R.id.fl_top)
        val includeTitle =
            LayoutInflater.from(requireContext()).inflate(R.layout.include_title, flTop)
        titleBar = includeTitle.findViewById(R.id.title_bar)
        titleBar.leftText.compoundDrawableTintList = ColorStateList.valueOf(Color.WHITE)
        super.onViewCreated(view, savedInstanceState)
    }

    //初始化titleBar 传入字符串资源时自动展示，默认是不禁用左侧返回键的, 默认禁用右侧编辑
    fun initTitleBar(
        title: String = "",
        isDisableLeft: Boolean = false,
    ) {
        if (isDisableLeft) titleBar.disableLeftView()
        titleBar.setTitle(title).centerText.typeface = Typeface.defaultFromStyle(Typeface.BOLD)

        titleBar.setLeftClickListener {
            onLeftClickListener()
        }

    }


    open fun onLeftClickListener() {
        navigateUp()
    }

    protected fun onEditClickListener() {

    }
}

